************************************************************
****************** REPLICATION CODE ************************
************************************************************
* For: Rigterink, The Wane of Command, APSR				   *
* Tables and Figures in article main text				   *
************************************************************
* Content of file:										   *
/*														   *
1. Preliminaries and setting directory					   *
2. Programs needed to produce main results				   *
3. Balance Table										   *
4. Descriptive statistics								   *
5. Some datawork										   *
6. Main result											   *
7. Robustness											   *
8. Theoretical explanations								   *
*/														   *
************************************************************

/*----------------------------------------------------------
---------- Preliminaries and setting directory -------------
----------------------------------------------------------*/

clear all
version 14
set more off

*******************************
*** Set your directory here ***
*******************************
cd "[directory]"

cap log close
log using log\Rigterink_drones_replication_maintext.log, replace


/*----------------------------------------------------------
---------Programs needed to produce main results -----------
----------------------------------------------------------*/

* To calculate Wald statistics for joint significance of coefficients 
prog define Fstats, eclass
{
capture noisily: testparm L*_bigfishdied
capture: eret scalar lagF = r(p)
capture noisily: testparm F*_bigfishdied
capture: eret scalar leadF = r(p)
capture: testparm L*_bigfishtarget
capture: eret scalar lagFtarget = r(p)
capture: testparm F*_bigfishtarget
capture: eret scalar leadFtarget = r(p)
local depvar = e(depvar)
sum `depvar' if (L1_bigfishtarget==1 & L1_bigfishdied==0) | (L2_bigfishtarget==1 & L2_bigfishdied==0) | (L3_bigfishtarget==1 & L3_bigfishdied==0) | (L4_bigfishtarget==1 & L4_bigfishdied==0) | (L5_bigfishtarget==1 & L5_bigfishdied==0) | (L6_bigfishtarget==1 & L6_bigfishdied==0) 
eret scalar cmean = r(mean)
}

end

* Calculating coefficients subject to quadratic constraint 
do "do/quadratic.do"


/*----------------------------------------------------------
---------------------- Balance table -----------------------
----------------------------------------------------------*/

use "dta/Rigterink_drones_replication_strikeleveldata.dta", clear

* Defining all variables to go in balance table
global balance "strikesprev6month hitprev6month missprev6month pakmilprev* pakmildayprev* peac*prev* *next6month year reward noincommand mincas-maxinj totlead areadum* typedum* groupdum*"

* Generating balance table
balancetable bigfishdied $balance using tables/Rigterink_Tab2.tex, replace wide(mean1 mean2 pval) pvalues ctitles("Mean miss" "Mean hit" "p-value difference" "Observations") varlabels nopar staraux


/*----------------------------------------------------------
----------------- Descriptive statistics -------------------
----------------------------------------------------------*/

use "dta/Rigterink_drones_replication_descriptives.dta", clear

* Defining all variables to calculating descriptive statistics for
local allvars terratt unclaimed claimed p_success pakall afgh row meanndead ///
targetpri targetciv targetmil killwoundus pakmil peace dronestrike firstatt infight

* Calculating summary statistics
format `allvars' %9.3f
fsum `allvars', format(%9.3f) uselabel

* Outputting table
estpost summarize `allvars'
esttab using tables/Rigterink_Tab3.tex, replace cells("count mean sd min max") b(%9.3f) label nomtitle nonumber noobs


/*----------------------------------------------------------
--------------------- Some datawork ------------------------
----------------------------------------------------------*/

use "dta/Rigterink_drones_replication_descriptives.dta", clear

* Relabelling so labels will fit table column headers
label var terratt "Terr. att."
label var unclaimed "Unclaimed"
label var claimed "Claimed"
label var p_success "% success"
label var meanndead "mean # vics."
label var targetpri "Private"
label var targetciv "Civilian"
label var targetmil "Military"
label var pakall "Pak."
label var row "ROW"
label var afgh "Afgh."
label var stanfordaffil "Affil. att."
label var firstatt "Splintering"
label var killwoundus "US vic."
label var infight "Infight"

* Logging all count variables
gen terratt_unlog = terratt 
label var terratt_unlog "Terr. att."

for var terratt unclaimed claimed targetpri targetciv targetmil ///
terrattexAQ pakall row afgh killwoundus infight stanfordaffil ///
stanfminAQ stanfminisis stanfordtargetpri stanfordtargetciv stanfordtargetmil ///
stanfordmeanndead stanfordkillwoundus: ///
replace X = ln(X+1)

* Generating lags of all relevant variables and labelling them
set more off

forvalues k = 1/6 {
	foreach X of varlist dronestrike mincivcas maxcivcas mincas maxcas ///
	dronestrikedum bigfishtarget bigfishdied bigfishinv hvttarget hvtdied pakmil ///
	peace bigfish*_reward bigfish*_firsthitmiss bigfish*_centraltie ///
	bigfish*_vanguard bigfish*_integ bigfish*_firstincom civonlyl civonlys {
		gen L`k'_`X' = L`k'.`X'
		label var L`k'_`X' "t+`k'"
		gen F`k'_`X' = F`k'.`X'
		label var F`k'_`X' "t-`k'"
	}
	
}


for var bigfishtarget bigfishdied hvttarget hvtdied civonlys civonlyl maxcivcas civonlyl: label var X "t"

save "dta/Rigterink_drones_replication_maindataset.dta", replace


/*----------------------------------------------------------
---------------------- Main result -------------------------
----------------------------------------------------------*/

use "dta/Rigterink_drones_replication_maindataset.dta", clear

******************************
*** Baseline specification ***
******************************

reghdfe terratt F*bigfishtarget bigfishtarget L*_bigfishtarget F*bigfishdied bigfishdied L*_bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))

* Storing estimates
estimates store baseline

* Storing coefficients to interpret size
matrix coefs = e(b)

* Calculating Wald statistic for joint significance
Fstats

* Unlogged estimate of control mean for text
di exp(e(cmean))

* p-values F-test for graphs
testparm L*_bigfishdied
local lagF = round(r(p), 0.0001)
testparm F*_bigfishdied
local leadF = round(r(p), 0.0001)
testparm L*_bigfishtarget
local lagFtarget = round(r(p), 0.0001)
testparm F*_bigfishtarget
local leadFtarget = round(r(p), 0.0001)

****************
*** Figure 1 ***
****************

* Generating results with quadratic constraints

DefineQuadraticConstraintsM

cnsreg terratt L*_bigfishdied F*bigfishdied L*_bigfishtarget i.period i.groupid F*bigfishtarget bigfishtarget bigfishdied *dronestrike, constraints(MyBigConstraint)
estimates store qconstrained
Fstats

* Plotting results

coefplot (qconstrained, lcolor(gray) keep(L*bigfishdied) recast(line) ciopts(color(dimgray) recast(rarea))) /// 
(baseline,  mcolor(black) keep(*bigfishdied bigfishdied) ciopts(lcolor(black) recast(rcap))), ///
vert order(F9_* F8_* F7_* F6_* F5_* F4_* F3_* F2_* F1_* bigfish* L1_* L2_* L3_* L4_* L5_* L6_* L7_* L8_* L9_*) ///
yline(0, lcolor(black)) xline(7, lcolor(red)) nooffsets ///
plotregion(style(none)) graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
ytitle("Coefficient estimate on hit") ///
legend(off) ///
groups(L*_bigfishdied = "Prob > F lags: `: di %9.4f `lagF''" F*_bigfishdied = "Prob > F leads: `: di %9.4f `leadF''", nogap) ///
saving(graphs/coefhit, replace)

coefplot /// 
(baseline,  mcolor(black) keep(*bigfishtarget bigfishtarget) ciopts(lcolor(black) recast(rcap))), ///
vert order(F9_* F8_* F7_* F6_* F5_* F4_* F3_* F2_* F1_* bigfish* L1_* L2_* L3_* L4_* L5_* L6_* L7_* L8_* L9_*) ///
yline(0, lcolor(black)) xline(7, lcolor(red)) nooffsets ///
plotregion(style(none)) graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
ytitle("Coefficient estimate on targeted") ///
yscale(range(-0.5 1)) ytick(-0.5(0.5)1) ylabel(-0.5(0.5)1) ///
legend(off) ///
groups(L*_bigfishtarget = "Prob > F lags: `: di %9.4f `lagFtarget''" F*_bigfishtarget = "Prob > F leads: `: di %9.4f `leadFtarget''", nogap) ///
saving(graphs/coefattempt, replace)

* Combining into single graph

graph combine graphs/coefhit.gph graphs/coefattempt.gph, rows(1) ///
graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
title("Terrorist attacks", color(black)) ///
xsize(7)

graph export graphs/Rigterink_Fig1.pdf, replace

* Retrieving coefficient sizes from matrix
clear
svmat coefs

* Keeping only lags of drone hit
keep coefs21-coefs26
gen id=_n
reshape long coefs, i(id) j(time)
replace time = time-20
drop id

* Taking exponent of effect size
gen effecthit = exp(coefs)

* Unlogged estimates of impact of 'hit', average and for each lag
sum effecthit
list time effecthit


/*----------------------------------------------------------
----------------------- Robustness -------------------------
----------------------------------------------------------*/

***************
*** Table 4 ***
***************

use "dta/Rigterink_drones_replication_daystofirstattack.dta", clear

* Regressions

xtreg distany bigfishdied, fe vce(cluster groups)
estimates store m1
outreg2 m1 using tables/Rigterink_Tab4, replace label ctitle("OLS", "First", "terrorist", "attack") addtext("Group FE", "YES", "Stratified on group", "NO") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

stset distany, fail(unclaim)
estimates store m2
stcox bigfishdied, vce(cluster groups) efron nohr strata(groups)
outreg2 m2 using tables/Rigterink_Tab4, append label ctitle("cox", "First", "terrorist", "attack") addtext("Group FE", "NO", "Stratified on group", "YES") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

xtreg distclaim bigfishdied, fe vce(cluster groups)
estimates store m3
outreg2 m3 using tables/Rigterink_Tab4, append label ctitle("OLS", "First", "claimed", "attack") addtext("Group FE", "YES", "Stratified on group", "NO") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

stset distclaim, fail(claim)
stcox bigfishdied, vce(cluster groups) efron nohr strata(groups)
estimates store m4
outreg2 m4 using tables/Rigterink_Tab4, append label ctitle("cox", "First", "claimed", "attack") addtext("Group FE", "NO", "Stratified on group", "YES") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

xtreg distunclaim bigfishdied, fe vce(cluster groups)
estimates store m5
outreg2 m5 using tables/Rigterink_Tab4, append label ctitle("OLS", "First", "unclaimed", "attack") addtext("Group FE", "YES", "Stratified on group", "NO") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

stset distunclaim, fail(unclaim)
stcox bigfishdied, vce(cluster groups) efron nohr strata(groups)
estimates store m6
outreg2 m6 using tables/Rigterink_Tab4, append tex(frag) label ctitle("cox", "First", "unclaimed", "attack") addtext("Group FE", "NO", "Stratified on group", "YES") ///
nonotes addnote("Clustered (group) standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")


****************
*** Figure 2 ***
****************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

* Extending dataset to 15 leads and lags

forvalues k = 7/15 {
	foreach X of varlist bigfishtarget bigfishdied dronestrike {
		gen L`k'_`X' = L`k'.`X'
		label var L`k'_`X' "t+`k'"
		gen F`k'_`X' = F`k'.`X'
		label var F`k'_`X' "t-`k'"
	}
	
}

* Regression with 15 leads and lags

reghdfe terratt F*bigfishtarget bigfishtarget L*_bigfishtarget F*bigfishdied bigfishdied L*_bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
estimates store coefficients15
Fstats

* Saving coefficients to matrix
matrix coefs15 = e(b)

* Left-hand panel
coefplot ///
(coefficients15, mcolor(black) ciopts(lcolor(black)) keep(bigfishdied L*bigfishdied) label("Coefficient estimates on hit")) ///
(coefficients15, mcolor(gray) ciopts(lcolor(gray) lpattern(dash)) keep(bigfishtarget L*bigfishtarget) label("Coefficient estimates on targeted")) ///
, vert ///
order(bigfish* L1_* L2_* L3_* L4_* L5_* L6_* L7_* L8_* L9_* L10_* L11_* L12_* L13_* L14*_ L15*) ///
plotregion(style(none)) graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
ytitle("Coefficient estimate") ///
yline(0, lcolor(black)) xline(1, lcolor(red)) legend(row(4)) nooffsets ///
xtick(1(2)31) xlabel(1 "t" 3 "t+1" 5 "t+2" 7 "t+3" 9 "t+4" 11 "t+5" 13 "t+6" 15 "t+7" 17 "t+8" 19 "t+9" 21 "t+10" 23 "t+11" 25 "t+12" 27 "t+13" 29 "t+14" 31 "t+15", labsize(small)) 

graph save graphs/combine_speedup1.gph, replace
 
* Retrieving estimates from matrix
clear
svmat coefs15

* Cleaning
keep coefs1516-coefs1531 coefs1547-coefs1562
rename (coefs151? coefs152? coefs153?) (coefs141? coefs142? coefs143?)

forvalues i = 16(1)31 {
	local j = `i'-16
	rename coefs14`i' coefs14`j'
}

forvalues i = 47(1)62 {
	local j = `i'-47
	rename coefs15`i' coefs15`j'
}
gen id = _n

reshape long coefs15 coefs14, i(id) j(time)
rename (coefs14 coefs15) (coefattempt coefhit)

* Right-hand panel
graph twoway (fpfitci coefhit time if time!=0, lcolor(black) fcolor(gs13) alcolor(gs13) estopts(degree(2))) ///
(fpfitci coefattempt time if time!=0, clcolor(gs10) fcolor(none) alcolor(gs10) alpattern(dash) estopts(degree(2))) ///
(scatter coefhit time, mcolor(black)) ///
(scatter coefattempt time, mcolor(gray)), ///
plotregion(style(none)) graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
xtick(0(1)15) xlabel(0 "t" 1 "t+1" 2 "t+2" 3 "t+3" 4 "t+4" 5 "t+5" 6 "t+6" 7 "t+7" 8 "t+8" 9 "t+9" 10 "t+10" 11 "t+11" 12 "t+12" 13 "t+13" 14 "t+14" 15 "t+15", labsize(small)) ///
ytitle("Coefficient estimate") ///
yline(0, lcolor(black)) xline(0, lcolor(red)) ///
legend(order(2 4) label(2 "cubic trend hit and 95% CI") label(4 "cubic trend targeted and 95% CI") row(2)) ///
yscale(range(-1 1)) ytick(-1(0.5)1) ylabel(-1(0.5)1) ///
xtitle("")

graph save graphs/combine_speedup2.gph, replace

* Combining both panels
graph combine graphs/combine_speedup1.gph graphs/combine_speedup2.gph, rows(1) ///
graphregion(ifcolor(white) fcolor(white) color(white) icolor(white)) ///
title("Terrorist attacks", color(black)) ///
xsize(7)

graph export graphs/Rigterink_Fig2.pdf, replace


***************
*** Table 5 ***
***************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

* Baseline

reghdfe terratt F*bigfishtarget bigfishtarget L*_bigfishtarget F*bigfishdied bigfishdied L*_bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, replace label tex(frag) ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Baseline", "Terr.att.") 

* Not controlling for drone strikes
reghdfe terratt *bigfishtarget *bigfishdied, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("No", "controls", "Terr.att.")

* Leader Fixed effects
reghdfe terratt *bigfishtarget *bigfishdied bigfishdum* *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "YES") ///
nonotes addnote("Standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Baseline", "Terr.att.") 

* Controlling for Pakistani military action 
reghdfe terratt *bigfishtarget *bigfishdied *pakmil *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Pak. mil", "action", "6L\&Ls", "Terr.att.")

* Controlling for peace agreement
reghdfe terratt *bigfishtarget *bigfishdied *peace *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Peace", "agreem.", "6L\&Ls", "Terr.att.")

* Alternative treatment AQ
reghdfe terrattexAQ *bigfishtarget *bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Alt.", "aggreg.", "AQ", "Terr.att.")

* Alternative treatment 'local Taliban' and TTP
preserve

replace groupid=9 if groupid==12 & periodid>47 

collapse (rawsum) terratt_unlog terrattexAQ *dronestrike (max) *bigfishtarget *bigfishdied, by(groupid periodid)

gen terratt = ln(terratt_unlog+1)

label var terratt "Terr. att."

reghdfe terratt *bigfishtarget *bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Alt.", "aggreg.", "TTP", "Terr.att.")

restore

* Alternative leader coding

preserve

drop F*_bigfishdied L*_bigfishdied bigfishdied F*_bigfishtarget L*_bigfishtarget bigfishtarget
rename (L?_hvtdied F?_hvtdied hvtdied L?_hvttarget F?_hvttarget hvttarget) (L?_bigfishdied F?_bigfishdied bigfishdied L?_bigfishtarget F?_bigfishtarget bigfishtarget)

reghdfe terratt *bigfishtarget *bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats

outreg2 using tables/Rigterink_Tab5, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec (4) ///
addtext("Group FE", "YES", "Period FE", "YES", "Leader FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01") ///
ctitle("Alt.", "leader.", "coding", "Terr.att.")

restore


/*----------------------------------------------------------
---------------- Theoretical explanations ------------------
----------------------------------------------------------*/

***************
*** Table 6 ***
***************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

foreach  X of varlist targetciv targetpri unclaimed firstatt infight claimed {

	if "`X'"=="targetciv" {
		local tablemethod = "replace"
		}
	else {
		local tablemethod = "append"
	}
	

	reghdfe `X' *bigfishtarget *bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(,bw(12))
	Fstats

	outreg2 using tables/Rigterink_Tab6, `tablemethod' label tex(frag)  ///
	keep(bigfishdied L*_bigfishdied) ///
	adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
	addtext("Group FE", "YES", "Month FE", "YES") ///
	nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

}


***************
*** Table 7 ***
***************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

* To calculate Wald statistic for joint significant interaction effects

prog define Fstatint, eclass 
{
testparm L?_bigfishdied_*
eret scalar lagint = r(p)
testparm F?_bigfishdied_*
eret scalar leadint = r(p)
}

end

* Groups relying on strong central ties 

preserve

rename (*bigfishtarget_centraltie *bigfishdied_centraltie) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, replace label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter.", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "central control", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore 

* Integrated groups 

preserve

rename (*bigfishtarget_integ *bigfishdied_integ) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter.", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "intregated", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore 

* Vanguard groups 

preserve

rename (*bigfishtarget_vanguard *bigfishdied_vanguard) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter.", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "vanguard", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore

* Differential effect each strike up to first hit

preserve

rename (*bigfishtarget_firsthitmiss *bigfishdied_firsthitmiss) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter. ", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "1st hit", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore 

* Leader reward

preserve 

rename (*bigfishtarget_reward *bigfishdied_reward) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter.", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "reward", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore 

* Position in organisation 

preserve

rename (*bigfishtarget_firstincom *bigfishdied_firstincom) (*bigfishtarget_interaction *bigfishdied_interaction)

reghdfe terratt *bigfishtarget *bigfishdied *bigfishtarget_interaction *bigfishdied_interaction *dronestrike, absorb(i.groupid i.periodid) vce(, bw(12))
Fstats
Fstatint

outreg2 using tables/Rigterink_Tab7, append label tex(frag)  ///
keep(bigfishdied L*_bigfishdied bigfishdied_* L?_bigfishdied_*) ///
adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags inter. ", e(lagint), "Prob $>$ F leads inter. ", e(leadint), "Control mean", e(cmean)) adec(4) ///
addtext("Interaction variable", "1st in comm.", "Group FE", "YES", "Period FE", "YES") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore


***************
*** Table 8 ***
***************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

foreach  X of varlist p_success meanndead targetmil killwoundus pakall afgh row  {

	if "`X'"=="p_success" {
		local tablemethod = "replace"
		}
	else {
		local tablemethod = "append"
	}
	
	
	reghdfe `X' *bigfishtarget *bigfishdied *dronestrike, absorb(i.groupid i.periodid) vce(,bw(12))
	Fstats

	outreg2 using tables/Rigterink_Tab8, `tablemethod' label tex(frag)  ///
	keep(bigfishdied L*_bigfishdied) ///
	adds("Prob $>$ F lags hit", e(lagF), "Prob $>$ F leads hit", e(leadF), "Prob $>$ F lags targeted", e(lagFtarget), "Prob $>$ F leads targeted", e(leadFtarget), "Control mean", e(cmean)) adec(4) ///
	addtext("Group FE", "YES", "Month FE", "YES") ///
	nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

}


***************
*** Table 9 ***
***************

use "dta/Rigterink_drones_replication_maindataset.dta", clear

*** Using high casualty estimate ***

* # of civilians casualties as 'treatment', # casualties as 'control'
reghdfe terratt *maxcivcas *maxcas, absorb(i.groupid i.periodid) vce(, bw(12))
testparm L?_maxcivcas
local lagF = round(r(p), 0.0001)
testparm F?_maxcivcas
local leadF = round(r(p), 0.0001)

outreg2 using tables/Rigterink_Tab9, replace label tex(frag)  ///
keep(maxcivcas L*_maxcivcas) ///
adds("Prob $>$ F lags", `lagF', "Prob $>$ F leads", `leadF') adec (4) ///
addtext("Indep. var.", "# civ", "Control", "# cas", "Model", "Gr-mnth", "Group FE", "YES", "Period FE", "YES", "Time trend", "NO", "Affiliate FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

* Only civilian casualties as 'treatment', any drone strike as 'control'
preserve

drop *maxcivcas *maxcas
rename (*civonlyl *dronestrikedum) (*maxcivcas *maxcas)

reghdfe terratt *maxcivcas *maxcas, absorb(i.groupid i.periodid) vce(, bw(12))
testparm L?_maxcivcas
local lagF = round(r(p), 0.0001)
testparm F?_maxcivcas
local leadF = round(r(p), 0.0001)

outreg2 using tables/Rigterink_Tab9, append label tex(frag)  ///
keep(maxcivcas L*_maxcivcas) ///
adds("Prob $>$ F lags", `lagF', "Prob $>$ F leads", `leadF') adec (4) ///
addtext("Indep. var.", "only civ", "Control", "strike", "Model", "Gr-mnth", "Group FE", "YES", "Period FE", "YES", "Time trend", "NO", "Affiliate FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore

*** Aggregating all groups ***

preserve

collapse (rawsum) terratt maxcivcas maxcas (max) civonlyl dronestrikedum, by(periodid)

tsset periodid

label var terratt "Terr. att."
forvalues i = 1(1)6 {
	for var maxcivcas maxcas civonlyl dronestrikedum: gen F`i'_X = F`i'.X \ gen L`i'_X = L`i'.X
	for var L`i'_*: label var X "t+`i'"
}
	
for var maxcas maxcivcas civonlyl dronestrikedum: label var X "t"

* # of civilians casualties as 'treatment', # casualties as 'control'
newey terratt *maxcivcas *maxcas periodid, lag(12)
testparm L?_maxcivcas
local lagF = round(r(p), 0.0001)
testparm F?_maxcivcas
local leadF = round(r(p), 0.0001)

outreg2 using tables/Rigterink_Tab9, append label tex(frag) nocons ///
keep(maxcivcas L*_maxcivcas) ///
adds("Prob $>$ F lags", `lagF', "Prob $>$ F leads", `leadF') adec (4) ///
addtext("Indep. var.", "# civ", "Control", "# cas", "Model", "Month", "Group FE", "NO", "Period FE", "NO", "Time trend", "YES", "Affiliate FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

* Only civilian casualties as 'treatment', any drone strike as 'control'
drop *maxcivcas *maxcas
rename (*civonlyl *dronestrikedum) (*maxcivcas *maxcas)

newey terratt *maxcivcas *maxcas periodid, lag(12)
testparm L?_maxcivcas
local lagF = round(r(p), 0.0001)
testparm F?_maxcivcas
local leadF = round(r(p), 0.0001)

outreg2 using tables/Rigterink_Tab9, append label tex(frag) nocons ///
keep(maxcivcas L*_maxcivcas) ///
adds("Prob $>$ F lags", `lagF', "Prob $>$ F leads", `leadF') adec (4) ///
addtext("Indep. var.", "only civ", "Control", "strike", "Model", "Month", "Group FE", "NO", "Period FE", "NO", "Time trend", "YES", "Affiliate FE", "NO") ///
nonotes addnote("Newey-West standard errors in parentheses", "* p<0.1 ** p<0.05 *** p<0.01")

restore 


*** Using low casualty estimates, mentioned but not shown in paper 

* Low estimate
reghdfe terratt *mincivcas *mincas, absorb(i.groupid i.periodid) vce(, bw(12))
testparm L?_mincivcas
local lagF = round(r(p), 0.0001)
testparm F?_mincivcas
local leadF = round(r(p), 0.0001)

reghdfe terratt *civonlys *dronestrikedum, absorb(i.groupid i.periodid) vce(, bw(12))
testparm L?_civonlys
local lagF = round(r(p), 0.0001)
testparm F?_civonlys
local leadF = round(r(p), 0.0001)


*******************
*** END OF FILE ***
*******************
